package com.lks.common.interceptor;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.lks.users.pojo.AAdmins;
import com.lks.users.service.IUsersService;

/**
 * 管理员的拦截器
 * 
 * @author lks
 * @2016年11月29日
 * @下午9:04:21
 */
@Component("adminsAuthInterceptor")
public class AdminsAuthInterceptor extends HandlerInterceptorAdapter
{
	@Resource
	private IUsersService usersService;

	/**
	 * 在拦截之前，进行判断,写完拦截器进行配置拦截器
	 */
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
	{
		HttpSession session = request.getSession();

		AAdmins admins = (AAdmins) session.getAttribute("admins");
		if (admins != null)
		{
			/* 已登录 */
			return true;
		}

		/* 非法访问 */
		String info = "请先登录";
		session.setAttribute("info", info);
		/* 跳转到登录页面 */
		response.sendRedirect(request.getContextPath() + "/adminsLogin.htm");
		return false;
	}

}
